package whut.commons;

// bean class to represent location

public class Location implements Comparable<Location>{
	// store the Location in an array to accommodate multi-dimensional problem space
	private double[] loc;
	private double[] extended;

	public Location(double[] loc) {
		super();
		this.loc = loc;
	}

	public double[] getLoc() {
		return loc;
	}

	public void setLoc(double[] loc) {
		this.loc = loc;
	}

	public double[] getExtended() {
		return extended;
	}

	public void setExtended(double[] extended) {
		this.extended = extended;
	}

	@Override
	public int compareTo(Location o) {
		for (int i = 0; i < loc.length; i++) {
			int t = Double.compare(loc[i], o.loc[i]);
			if (t != 0){
				return t;
			}
		}
		return 0;
	}

	@Override
	public String toString() {
		StringBuilder sb = new StringBuilder();
		sb.append("Loc:[");
		for (int i = 0; i < loc.length - 1; i++) {
			sb.append(String.format("%.4E, ", loc[i]));
		}
		sb.append(String.format("%.4E]", loc[loc.length - 1]));

		if (extended != null){
			sb.append("\t\tvalues :[");
			for (int i = 0; i < extended.length - 1; i++) {
				sb.append(String.format("%.4E, ", extended[i]));
			}
			sb.append(String.format("%.4E]", extended[extended.length - 1]));
		}

		return sb.toString();
	}
}
